package com.Hermes.User;

import com.Hermes.Omega.Omega;
import com.Hermes.Omega.PK;
import it.unisa.dia.gas.jpbc.Element;

import java.math.BigInteger;
import java.util.ArrayList;

public class PreEnc {
    private final Element[][] Encnode;//0:x,1:y
    private final Element[][] Encesd;

    public PreEnc(ArrayList<node> apl, Floyd_Warshall fw, Omega omega, PK pk) {
        long preEncst = System.currentTimeMillis();
        Encesd = new Element[apl.size()][apl.size()];
        Encnode = new Element[apl.size()][2];
        for (int i = 0; i < apl.size(); i++) {
            Element[] res = new Element[2];
            long oneNodest = System.currentTimeMillis();
            res[0] = omega.Enc(new BigInteger(String.valueOf(apl.get(i).x)));
            res[1] = omega.Enc(new BigInteger(String.valueOf(apl.get(i).y)));
            long oneNodeet = System.currentTimeMillis();
//            System.out.println("加密一对坐标(oneNodeet-oneNodest) = " + (oneNodeet - oneNodest));
            Encnode[apl.get(i).index] = res;
        }
        var g = fw.getGraph();
        for (int i = 0; i < apl.size(); i++) {
            for (int j = 0; j < i; j++) {
                int dis = g[i][j];
                Element tmp = omega.Enc(new BigInteger(String.valueOf(dis)));
                Encesd[i][j] = tmp;
                Encesd[j][i] = tmp;
            }
        }
        long preEnced = System.currentTimeMillis();
        System.out.println("预加密(preEnced-preEncst) = " + (preEnced - preEncst));

    }

    public Element[][] getEncnode() {
        return Encnode;
    }

    public Element[][] getEncesd() {
        return Encesd;
    }
}
